// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: ProDetailAction.java

package com.market.web.action;

import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.springframework.beans.BeanUtils;

import com.market.bean.Beer;
import com.market.bean.Product;
import com.market.bean.Rice;
import com.market.bean.Safety;
import com.market.web.form.BeerForm;
import com.market.web.form.RiceForm;
import com.market.web.form.SafetyForm;

// Referenced classes of package com.market.web.action:
// ProductAction

public class ProDetailAction extends ProductAction
{

    public ProDetailAction()
    {
    }

    public String execute() throws Exception
    {
        long id = getProductId();
        Product pro = getProductService().findById(id);
        if (pro == null)
        {
            ActionMessages error = new ActionMessages();
            error.add("org.apache.struts.action.GLOBAL_MESSAGE", new ActionMessage(
                    "Sorry,\u6CA1\u6709\u627E\u5230\u5546\u54C1!", false));
            //saveErrors(request, error);
            return INPUT;
            //return mapping.getInputForward();
        }
        else
        {
            setOtherInfo(pro.getCategory());
            setOtherProduct( pro);
            return processDetail(pro);
        }
    }

    private String processDetail(Product pro)
    {
        String category = pro.getCategory();
        if ("rice".equals(category))
        {
            RiceForm lf = new RiceForm();
            Rice lock = (Rice)getProductService().findById(com.market.bean.Rice.class, pro.getId());
            lock.setHot(lock.getHot() + 1);
            getProductService().saveOrUpdate(lock);
            BeanUtils.copyProperties(lock, lf);
            if (pro.getSupplierid() != 1L)
                setSSProduct( lf);
            getRequest().setAttribute("product", lf);
            return "balldetail";
            //return mapping.findForward("balldetail");
        }
        if ("beer".equals(category))
        {
            BeerForm elf = new BeerForm();
            Beer el = (Beer)getProductService().findById(com.market.bean.Beer.class, pro.getId());
            el.setHot(el.getHot() + 1);
            getProductService().saveOrUpdate(el);
            BeanUtils.copyProperties(el, elf);
            if (pro.getSupplierid() != 1L)
                setSSProduct(elf);
            getRequest().setAttribute("product", elf);
            return "bowbdetail";
            //return mapping.findForward("bowbdetail");
        }
        
        if ("safety".equals(category))
        {
            SafetyForm pmbf = new SafetyForm();
            Safety pmb = (Safety)getProductService().findById(com.market.bean.Safety.class, pro.getId());
            pmb.setHot(pmb.getHot() + 1);
            getProductService().saveOrUpdate(pmb);
            BeanUtils.copyProperties(pmb, pmbf);
            if (pro.getSupplierid() != 1L)
                setSSProduct( pmbf);
            getRequest().setAttribute("product", pmbf);
            return "safetydetail";
            //return mapping.findForward("safetydetail");
        }
        RiceForm hf = new RiceForm();
        Rice hw = (Rice)getProductService().findById(com.market.bean.Rice.class, pro.getId());
        hw.setHot(hw.getHot() + 1);
        getProductService().saveOrUpdate(hw);
        BeanUtils.copyProperties(hw, hf);
        if (pro.getSupplierid() != 1L)
            setSSProduct( hf);
        getRequest().setAttribute("product", hf);
        return "bowadetail";
        //return mapping.findForward("bowadetail");
    }
}
